/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!				\file		MainWindow.h
				\date		june 2010
				\author		TNick

				\brief		Defines MainWindow class


	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Please read ReadMe.txt and Licence.txt in root folder
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef		__MAINWINDOW_INC__
#define		__MAINWINDOW_INC__
#ifdef		__cplusplus
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QtGui>
#include	<QtGui/QMainWindow>
#include	<QSettings>

#include	<main.h>
#include	"MdiDraw.h"
#include	<base/CC_App.h>
#include	<base/CC_Err.h>

/*  INCLUDES    ============================================================ */
//
//
//
//




/* ------------------------------------------------------------------------- */
#include	"auto_acindex.h"
/* ========================================================================= */


/* ------------------------------------------------------------------------- */
namespace   PRD_M	{
	enum	    enumPRDM	{

			/// this menu holds file related actions
			FILE = 0,
			/// Inside File; groups together all recent files
			F_RECENT,
			/// this menu holds actions that change drawing in generic ways
			EDIT,
			/// toogle visibility status of main components and others
			VIEW,
			/// Inside View; groups all available skins
			V_SKIN,
			/// Inside View; groups available style sheets
			V_SSHEET,
			/// window manipulation, arrangement and list
			WINDOW,
			/// path to helpfull resources and informations about program
			HELP,


			/// validity check, space allocation
			MAX

		};// enum enumPRDM
} // namespace PRD_M
/* ========================================================================= */


/* ------------------------------------------------------------------------- */
namespace   PRD_TB	{
	enum	    enumPRDTB	{

			/// holds file related actions
			FILE = 0,
			/// holds actions that change drawing in generic ways
			EDIT,
			/// toogle visibility status of main components
			VIEW,


			/// validity check, space allocation
			MAX

		};// enum PRD_TB
} // namespace PRD_TB
/* ========================================================================= */


/* ------------------------------------------------------------------------- */
namespace   PRD_DK	{
	enum	    enumPRDDK	{

			PROP = 0,
			EXPLORER,
			CMDOUT,


			/// validity check, space allocation
			MAX

		};// enum enumPRDDK
} // namespace PRD_DK
/* ========================================================================= */




namespace Ui {
	class MainWindow;
}

/// main panel here
/**
*
*/
class MainWindow : public QMainWindow
{
	Q_OBJECT

	friend class CC_Err;

	//
	//
	//
	//
	/*  DEFINITIONS    --------------------------------------------------------- */


	/*  DEFINITIONS    ========================================================= */
	//
	//
	//
	//
	/*  DATA    ---------------------------------------------------------------- */

	// internal variables

	/// pointer to central widget (container for MDI childs)
private:    QMdiArea*		mdiArea;

	/// cache a pointer to active window
private:	MdiDraw*		p_active_draw;

	/// global variable used to asign unique names for new files
private:	unsigned		uiNewFileNr;





	/// array of pointers to all predined actions
private:	QAction*		prdAct[PRD_A::MAX];
	/// array of pointers to all predined menus
private:	QMenu*			prdMnu[PRD_M::MAX];
	/// array of pointers to all predined toolbars
private:	QToolBar*		prdTlb[PRD_TB::MAX];
	/// array of pointers to all predined toolbars
private:	QDockWidget*	prdDks[PRD_DK::MAX];

	/// shall map signals, so to speak :)
private:	QSignalMapper*  windowMapper;



	/// command input text field
protected:	QTextEdit *		tx_cmd;
	/// command output text box
protected:	QTextEdit *		tx_out;

	/// the properties view
private:	QTreeView*	view_P;
	/// the explorer view
private:	QTreeView*	view_E;



	/* THIS PART DEALS WITH RECENT FILES */
	enum {
			/// the very top limit; above this it is an error
			MaxRecentFiles = 50
						 };

	/// maximum number of recent files in file menu
private:	int				iMaxRecFiles;

	/// actual list of recent files
private:	QStringList		slRecFiles;
	/* ---------------------------------- */


	/*  DATA    ================================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ----------------------------------------------------------- */

	/// the nice constructor
public:					MainWindow		(CC_Err* pErr, QWidget *parent = 0);
	/// the ugly constructor
public:					~MainWindow		();

	/* ------------------------------------------------------------- */
	/* initialization functions called only from constructor         */

	/// simply create actions and fill prdAct array
private: CCERR::EERRORS		Init_Acts	    (CC_Err* pErr);
	/// simply create prdined menus
private: CCERR::EERRORS		Init_Menus	    (CC_Err* pErr);
	/// simply create prdined toolbars
private: CCERR::EERRORS		Init_Toolbars	(CC_Err* pErr);
	/// simply create prdined docked panels
private: CCERR::EERRORS		Init_Docks		(CC_Err* pErr);
	/* ------------------------------------------------------------- */


	/// function that needs to be informed when a new drawing emerges
public: void			newMDI			(
			MdiDraw*	child	/**< pointer to newly created drawing */
			);

	/// close event
protected: void			closeEvent		(QCloseEvent *event);
	/// saves settings regarding the UI
private: void			SaveSettings	(void);
	/// adds a string as recent file, at the top of the list
private: void			AddRecentFile	(QString sNewFile);
	/// opens a new or existing drawing
private: void			NewDrawing		(QString sNewFile);
	/// returns a unique name for a drawing
public: inline QString	GetUniqName(void)
		{
			uiNewFileNr++;
			return QString(tr("Untitled %1").arg(uiNewFileNr));
		}
	/// tells if initialization of this class went OK
public: inline bool		InitOK			(void)
		{
			return (mdiArea != NULL);
		}
	/// tells if output window is visible or not
public: inline bool		IsOutVisible	(void)
		{
			if (prdDks[PRD_DK::CMDOUT] == NULL)
				return false;
			return (prdDks[PRD_DK::CMDOUT]->isVisible());
		}
	/// makes output window visible
public: inline bool		MakeOutVisible	(void)
		{
			if (prdDks[PRD_DK::CMDOUT] == NULL)
				return false;
			(prdDks[PRD_DK::CMDOUT]->setVisible(true));
			return true;
		}

	/// changes the menus according to current state
public:     void	updMenu		(void);


	/* ------------------------------------------------------------- */
	/* internal signaling                                            */
private slots:

	/// the user is given the oportunity to choose a file to open
	void	Slot_open			(void);
	/// a new drawing is created
	void	Slot_open_new		(void);
	void	Slot_open_recent	(void);
	/// current file is saved
	void	Slot_save			(void);
	/// current file is saved under a potentially diffrent name
	void	Slot_save_as		(void);
	void	Slot_print			(void);

	void	Slot_undo			(void);
	void	Slot_redo			(void);
	/// copy the selected item in clipboard
	void	Slot_cut			(void);
	/// copy the selected item in clipboard and then delete it
	void	Slot_copy			(void);
	/// insert content of the clipboard
	void	Slot_paste			(void);
	/// delete selection
	void	Slot_del			(void);

	void	Slot_about			(void);
	void	Slot_about_qt		(void);
	void	Slot_about_cgal		(void);

	void	Slot_ChangeSkin		(QAction* action);
	void	Slot_StyleSheet		(QAction* action);


	/// requests to change active MDI window (the drawing) changes
	void	Slot_ChangeActiveDraw(QWidget * window);
	/// informed when active MDI window (the drawing) changes
	void	Slot_ActiveDraw		(QMdiSubWindow * window);



	/* ------------------------------------------------------------- */


private:

	/// function to get a pointer to active drawing
	MdiDraw*	activeMdiChild			(void);
	/// the states and content of menus are updated
	void		updateWindowMenu		(void);
	/// shall change the direction of the layout
	void		switchLayoutDirection	(void);






	/*  FUNCTIONS    =========================================================== */
	//
	//
	//
	//

};	/*	class	MainWindow	*/
//
//
//
//
#endif	//	__cplusplus
#endif // __MAINWINDOW_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
